<template>
    <el-form :model="form" label-width="120px">
      <el-form-item label="姓名">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="form.age" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="form.region" placeholder="选择分类">
          <el-option label="画江湖之不良人" value="画江湖之不良人" />
          <el-option label="完美世界" value="完美世界" />
          <el-option label="吞噬星空" value="吞噬星空" />
          <el-option label="凡人修仙传" value="凡人修仙传" />
          <el-option label="斗破苍穹" value="斗破苍穹" />
          <el-option label="斗罗大陆" value="斗罗大陆" />
        </el-select>
      </el-form-item>
      <el-form-item label="时间">
        <el-col :span="11">
          <el-date-picker
            v-model="form.date1"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="填写日期"
            style="width: 100%"
          />
        </el-col>
        <el-col :span="2" class="text-center">
          <span class="text-gray-500">-</span>
        </el-col>
        <el-col :span="11">
          <el-time-picker
            v-model="form.date2"
            value-format="HH:mm:ss"
            placeholder="填写时间"
            style="width: 100%"
          />
        </el-col>
      </el-form-item>
     
      
      <el-form-item label="性别">
        <el-radio-group v-model="form.sex">
          <el-radio label="男" />
          <el-radio label="女" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="form.desc" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">Create</el-button>
        <el-button>Cancel</el-button>
      </el-form-item>
    </el-form>
  </template>
  
  <script setup>
  import { reactive } from 'vue'
  import useNewStore from '../store/index'
import  {useRouter } from 'vue-router'
import { PiniaVuePlugin } from 'pinia'
  // do not use same name with ref
  const form = reactive({
    name: '',
    age:'',
    region: '',
    date1: '',
    date2: '',
    sex: '',
    desc: '',
  })
  const store=useNewStore()
  const router=useRouter()
  const onSubmit = () => {
    console.log('submit!',form)
    // store里面 pinia add方法
    store.add(form)
    // 路由跳转
    router.push('/newlist')
  }
  </script>
  <style scoped>

  </style>